home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / progs / sviluppo / pike-0.4.0 / lib / include / simulate.pre.pike < prev    next >
Text File  |  1997-01-10  |  2KB  |  85 lines

  1. #include <process.h>
  2. #include <array.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. #define error(X) throw( ({ (X), backtrace()[0..sizeof(backtrace())-2] }) )
  7.  
  8. inherit "/precompiled/regexp";
  9.  
  10. varargs int member_array(mixed needle,mixed *haystack,int start)
  11. {
  12.   return search(haystack,needle,start);
  13. }
  14.  
  15. object previous_object()
  16. {
  17.   int e;
  18.   mixed **trace;
  19.   object o,ret;
  20.   trace=backtrace();
  21.   o=function_object(trace[-2][2]);
  22.   for(e=sizeof(trace)-3;e>=0;e--)
  23.   {
  24.     if(!trace[1][2]) continue;
  25.     ret=function_object(trace[1][2]);
  26.     if(o!=ret) return ret;
  27.   }
  28.   return 0;
  29. }
  30.  
  31. function this_function()
  32. {
  33.   return backtrace()[-2][2];
  34. }
  35.  
  36. string capitalize(string s)
  37. {
  38.   return upper_case(s[0..0])+s[1..sizeof(s)];
  39. }
  40.  
  41. function get_function(object o, string a)
  42. {
  43.   mixed ret;
  44.   ret=o[a];
  45.   return functionp(ret) ? ret : 0;
  46. }
  47.  
  48. string *regexp(string *s, string reg)
  49. {
  50.   
  51.   regexp::create(reg);
  52.   s=filter(s,match);
  53.   regexp::create(); /* Free compiled regexp */
  54.   return s;
  55. }
  56.  
  57. void create()
  58. {
  59.   add_constant("PI",3.1415926535897932384626433832795080);
  60.   add_constant("capitalize",capitalize);
  61.   add_constant("explode",`/);
  62.   add_constant("all_efuns",all_constants);
  63.  
  64.   add_constant("filter_array",filter);
  65.   add_constant("map_array",map);
  66.  
  67.   add_constant("get_function",get_function);
  68.   add_constant("implode",`*);
  69.   add_constant("m_indices",indices);
  70.   add_constant("m_sizeof",sizeof);
  71.   add_constant("m_values",values);
  72.   add_constant("member_array",member_array);
  73.   add_constant("previous_object",previous_object);
  74.   add_constant("regexp",regexp);
  75.   add_constant("strstr",search);
  76.   add_constant("sum",`+);
  77.   add_constant("this_function",this_function);
  78.   add_constant("add_efun",add_constant);
  79.  
  80.   add_constant("l_sizeof",sizeof);
  81.   add_constant("listp",multisetp);
  82.   add_constant("mklist",mkmultiset);
  83.   add_constant("aggregage_list",aggregate_multiset);
  84. }
  85.